package com.hz.ruoyifarmbase.basedata.controller;

import com.hz.ruoyifarmbase.basedata.domain.AgrBaseWorker;
import com.hz.ruoyifarmbase.basedata.service.AgrBaseWorkerService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author 侯文波
 * @date 2025/3/5 12:04
 * @description:
 */
@RestController
@RequestMapping("/worker")
public class AgrBaseWorkerController extends BaseController {
    @Autowired
    private AgrBaseWorkerService agrBaseWorkerService;

    @RequiresPermissions("basedata:worker:list")
    @GetMapping("/list")
    public TableDataInfo selectAgrBaseWorkerList(AgrBaseWorker agrBaseWorker){
        startPage();
        List<AgrBaseWorker> list = agrBaseWorkerService.selectAgrBaseWorkerList(agrBaseWorker);
        return getDataTable(list);
    }

    @RequiresPermissions("basedata:worker:add")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody AgrBaseWorker agrBaseWorker){
        return toAjax(agrBaseWorkerService.insertAgrBaseWorker(agrBaseWorker));
    }

    @RequiresPermissions("basedata:worker:update")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody AgrBaseWorker agrBaseWorker){
        return toAjax(agrBaseWorkerService.updateAgrBaseWorker(agrBaseWorker));
    }

    @RequiresPermissions("basedata:worker:delete")
    @DeleteMapping("/delete/{workerId}")
    public AjaxResult delete(@PathVariable Long workerId){
        return toAjax(agrBaseWorkerService.deleteAgrBaseWorkerByWorkerId(workerId));
    }

    @Log(title = "工人管理", businessType = BusinessType.EXPORT)
    @RequiresPermissions("basedata:worker:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response,AgrBaseWorker agrBaseWorker){

        List<AgrBaseWorker> list = agrBaseWorkerService.selectAgrBaseWorkerList(agrBaseWorker);
        ExcelUtil<AgrBaseWorker> excel = new ExcelUtil<AgrBaseWorker>(AgrBaseWorker.class);
        excel.exportExcel(response, list, "工人数据");
    }

    @PostMapping("/login")
    @CrossOrigin(origins = "*")
    public AjaxResult login(@RequestBody AgrBaseWorker agrBaseWorker){
        return agrBaseWorkerService.login(agrBaseWorker);
    }

    @GetMapping("/detail")
    @CrossOrigin(origins = "*")
    public AjaxResult detail(Long workerId){
        return agrBaseWorkerService.detail(workerId);
    }


    /**
     * 获取质量检测员
     * @return
     */
    @GetMapping("/check")
    @CrossOrigin(origins = "*")
    public List<Map<String, Object>> getWorkerCheck() {
        return agrBaseWorkerService.getWorkerCheck();
    }

}
